package com.sdtv.mediunfusion.base.config;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.sdtv.basemodule.config.AppHttpSetting;
import com.sdtv.basemodule.config.BaseConfig;
import com.sdtv.basemodule.http.interceptors.ParamInterceptor;
import com.sdtv.basemodule.rx.errorhandler.ResponseErrorListener;

import java.util.TreeMap;

/**
 * @ProjectName: MediunFusion
 * @Package: com.sdtv.mediunfusion.base
 * @ClassName: MediumConfig
 * @Description: java类作用描述
 * @Author: 小郭同学
 * @CreateDate: 2019-07-02 14:20
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class MediumConfig extends BaseConfig {

    private static final String TAG = "MediumConfig";

    public MediumConfig(Application application) {
        super(application);
    }

    @Override
    public ResponseErrorListener getResponseErrorListener() {
        return new ResponseErrorListener() {
            @Override
            public void handleResponseError(Context context, Throwable throwable) {
                //这里是错误处理类
                throwable.printStackTrace();
                Log.e(TAG, "handleResponseError: " + throwable.getMessage());
            }
        };
    }

    /**
     * 设置公共参数
     *
     * @return
     */
    @Override
    public ParamInterceptor getParamInterceptor() {
        return new ParamInterceptor() {
            @Override
            public TreeMap<String, String> dynamic(TreeMap<String, String> dynamicMap) {
                dynamicMap.put("terminal", AppConfig.TERMINAL);
                dynamicMap.put("version", AppConfig.APP_VERSION);
                dynamicMap.put("_timestamp", System.currentTimeMillis() + "");
                dynamicMap.put("userKey", "6bc2e90afbc24a5493096b5514362550");
                dynamicMap.put("_sign", "ddadf83db81538961ccffa361e902267");
                return dynamicMap;
            }
        };
    }

    /**
     * 设置放了请求
     *
     * @return
     */
    @Override
    public AppHttpSetting getHttpSetting() {
        return AppHttpSetting.builder()
                .with(getApplication())
                .setBaseUrl(AppConfig.HOST)
                .setHttpLog(true)
                .addInterceptor(getParamInterceptor())
                .build();
    }

    @Override
    public int getStatusColor() {
        return 0;
    }

}
